ICS3U: Introduction to Computer Science, Grade 11, University Preparation

Unit 2: Introduction to Programming

Activity 1: Creating Java Programs using Eclipse

Learning Goal: By the end of this activity, I will be able to create a simple Java Application using Eclipse, and upload my program to the GitHub website.

Content


GitHub Logo

Git is a distributed version control system that allows developers to track changes to their code, create backups and share their code in a team environment. GitHub is a web service that hosts Git repositories, plus many developer tools to aid in creating software projects.

We will be using GitHub, GitHub Classroom and EGit (part of the eclipse IDE) during this course to create and share assignment repositories. Each student will have a private repository for the activities and assignment associated with each programming unit as well as their RST.

The Eclipse IDE (Integrated Development Environment)

Eclipse is a program used by many professional programmers, and in many colleges and universities to train people in programming. It was first designed to program Java. It is a very flexible and powerful program that can now be used to program in many different programming languages.It can be used to program in C/C++/C#, Python, Ruby, etc ... by adding available modules to the program. Eclipse is free to download and open-source, which means that anyone can view the code used to create it.

Eclipse is one of many software applications that are to used to develop programs. These applications are called Integrated Development Environments or IDEs. IDEs have a history of their own. Most IDEs contain a text editor to edit the file, a file explorer to organize the source code (the files that contain the programming code) into projects, and various other features that help a developer write programs.

Usually IDEs also either connect to or provide a compiler, allow the developer to trace their code one line at a time, and provide context sensitive help. Eclipse provides a number of features that we will explore of the next few lessons.

HOME COMPUTERS/PERSONAL LAPTOPS: Download & Install Eclipse

ECLIPSE IS INSTALLED ON THE SCHOOL COMPUTER. Use the icon on the DESKTOP to launch Eclipse.

THESE INSTRUCTIONS EXPLAIN HOW TO INSTALL ECLIPSE ON YOUR HOME COMPUTER.

The Eclipse Workbench

The Eclipse Workbench consists of three main components: Perspectives, Views and Editors

GitHub Classroom

GitHub repository Link

Hapara evidence card

GitHub Classroom is a tool that your teacher will be using to create repositories on your behalf to store the code you will create this year. You will NOT need to make your own repositories - they will be created for you, and each repository will contain ONE Eclipse project to store your work for each unit.

You will receive a link to a new repository for each new coding unit in this course.

If you haven't already, head back to Hapara to link your GitHub account with GitHub Classroom and accept the Unit 2 Repository.

Git Repositories

The following image shows the various commands that you will need to work with GIT for your activities and assignments:

GIT workflow

The most important actions are clone/import, pull, and commit/push.

Clone/Import

To clone a repository means to create a local copy of the remote repository (hosted on GitHub) onto your local computer. This creates both the local repository (which tracks changes) as well as the working directory that contains your files. Once this is done you can import your project into Eclipse (though we will use a wizard that does both at the same time!)

Cloning/Importing involves these steps:

  1. Obtain the URL for your repository from the GitHub website and copy it to the clipboard.
    Clone Git Repository
  2. In Eclipse, select File ... Import
  3. Select Git ... Projects from Git
  4. Choose Clone URI
  5. The next screen should already be populated with your repository information. You will need to provide your GitHub authentication information.
    • Under "Authentication", enter your GitHub username and use a classic Personal Access Token (PAT) for the password.
      • NOTE: As of August 13, 2021, GitHub requires a personal access token (PAT) to use GitHub with 3rd party applications. You can find instructions on this link to create a CLASSIC PAT and use your PAT in place of your password in Eclipse.
      • Choose a custom expiry, and set it up to work for the entire course duration (Check the course calendar to be sure!)
      • Give your token repo scope.
    • Be sure to check the "Store in Secure Store" in Eclipse so you don't need to re-enter your PAT each time.
    GitHub Authentication
    GitHub Authentication
  6. In the "Branch Selection" screen, clear the checkbox for the feedback branch. Only the main branch is needed.
    Select Main Branch
  7. In the "Local Destination" screen, you can accept the default directory
  8. Under "Wizard for project import", choose Import existing Eclipse projects
    Import Existing Projects
  9. Click Finish
  10. Once your project has imported completely, rename your project (F2 or right click Refactor ... Rename) to include your last name (Format: Lastname_ICS3U_Unit2 ).
  11. Click HERE for a step by step video of the clone/import process.

Once your have completed these steps, you should have a copy of the project stored on your computer. You will need to complete this process for every computer that you will use for this course.

Commit/Push

Once you have made some changes to your project, you will want to add those changes to your remote repository. This serves as a backup of your work, allows your teacher to view and assess your work, and gives you the freedom to work from multiple computers. This process involves 3 steps: staging, committing, and pushing.

  1. To stage your work means that you are preparing to put your changes to the local repository.
    • This can be done using the Git Staging view, found in the Git perspective.
    • Once your files have been modified, they should appear in the "Unstaged Changes" window.
    • Add your files to the index (or Staged Changes list) by dragging and dropping, using the green plus signs, or right click and select Add to Index

Git staging view

  1. Once your changes have been staged, they are ready to be committed (to the local repository) and pushed (to the remote repository).
    • You MUST include a commit message every time you commit!
      • If you can't think of a message, ask yourself "Why is it important that I commit right now?"
    • Once your comment is entered, select Commit and Push ...

Git staging part 2

  1. Click HERE for a step by step video of the commit/push process.

Pull

If you switch between computers (home and school) it is CRITICAL that every coding session begin with a "Pull" command. This ensures you are always working on the latest version of your code.

  1. To issue a pull command, in the Git Repositories view, right click on your repository and select Pull from the context menu

Git pull command

  1. Click HERE for a step by step video of the pull process

Why Program in Java?

Java is an object-oriented programming language. Object-Oriented Programming (OOP) evolved out of the need to develop complex programs in a systematic, modular approach.

Objects, Classes, Packages & Applications

Class: DVD.  Attributes: title, genre, year, onLoad; method: loadToFriend()

Media Package containing DVD class and CD class

Package containing a Java Application

Your First Java Application

The following HelloWorld application is a simple, yet complete, Java program:

A first Java Application

The Parts of a Java Application
Statements
Comments
Did you know icon

Code conventions are a set of guidelines for writing an application. They provide details about commenting, rules for naming methods, classes, and packages, and statement formatting. They make programs easier to read and understand. Organizations that employ programmers often not only encourage the use of code conventions, but require it.

Through this course, code conventions will be introduced as needed. It is important that you pay attention to these conventions and use them when you write your code.

  • A Program Header should begin a program.
    • The comment should include information such as your name, class name, the date, and a brief statement about the program
  • Package names should begin with a lowercase letter and then an uppercase letter should begin each word within the name, no spaces!
  • Class names should be nouns and begin with an uppercase letter and an uppercase letter should begin each word within the name, no spaces!
  • A comment block should be included before each class and method.
    • Not typically placed before the main() method
  • An open curly brace { should be placed on the same line as the class or method declaration, and the closing curly brace } should be on a separate line and aligned with the class or method declaration

Evidence of Learning


Assignment IconStep by Step

Now it's time to create your first Java Application! Follow these instructions carefully:

Commit your progress to GitHub every day. You are getting assessed on the frequency of your commits, and the quality of your commit messages!